<template>
	<view class="container">
		<uv-navbar title="渠道配置" bg-color="none" @leftClick="leftClick"></uv-navbar>
		<view class="wx-box">
			<view class="name">商户名称</view>
			<view class="content">
				<uv-input v-model="name" placeholder="商户名称" border="none"></uv-input>
			</view>
			<view class="password">商户链接</view>
			<view class="content">
				<uv-input v-model="merchantLinkUrl" placeholder="商户链接" border="none"></uv-input>
			</view>
		</view>
		<view class="button-fb" @click="onSubmit">保存提交</view>
		<uv-loading-page :loading="loading" loading-mode="semicircle" bgColor="rgba(0, 0, 0, 0.2)"></uv-loading-page>
	</view>
</template>

<script>
	const app = getApp();
	import {
		merchantChannel,
	} from '@/common/api.js'
	import {
		toast
	} from '@/utils/common'
	export default {
		data() {
			return {
				loading: false,
				name: '',
				merchantLinkUrl: '',
				id: ''
			};
		},
		created() {
			// this.loading = true
			// setTimeout(() => {
			// 	this.loading = false
			// }, 2000)
		},
		onLoad(e) {
			this.id = e.id
		},
		methods: {
			leftClick() {
				app.navigateBack()
			},

			onSubmit() {
				if (!this.name) {
					uni.showModal({
						title: '提示',
						content: '请输入商户名称',
						showCancel: false
					})
					return false
				}
				if (!this.merchantLinkUrl) {
					uni.showModal({
						title: '提示',
						content: '请输入商户链接',
						showCancel: false
					})
					return false
				}
				uni.showLoading({
					mask: true,
					title: '保存中...'
				});
				let idArr = []
				switch (this.id) {
					case '美团':
						idArr = [4, 7]
						break;
					case '大众点评':
						idArr = [5, 8]
						break;
					case '高德地图':
						idArr = [6]
						break;
					case '抖音':
						idArr = [9]
						break;

				}
				idArr.forEach(item => {
					merchantChannel({
						merchantName: this.name,
						merchantLinkUrl: this.merchantLinkUrl,
						channelId: item
					}).then(res => {
						this.name = ''
						this.merchantLinkUrl = ''
						uni.hideLoading();
						toast('配置成功')
					}).catch(err => {
						uni.hideLoading();
					})
				})
			},
			onConnect() {

			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		overflow: hidden;
		min-height: 100vh;
		width: 100vw;
		padding: 40rpx;
		padding-top: 226rpx;
		// padding-bottom: calc(96rpx + 32rpx + 22rpx);
		box-sizing: border-box;
		background: radial-gradient(128% 128% at 95% 0%, #D7CEFF 0%, #BBE1FF 62%, #FFFFFF 95%);

		.button-fb {
			width: 480rpx;
			height: 96rpx;
			background: linear-gradient(180deg, #886AE6 0%, #4635FF 99%);
			border-radius: 48rpx;
			font-weight: 400;
			font-size: 32rpx;
			color: #FFFFFF;
			line-height: 96rpx;
			text-align: center;
			margin: 0 auto;
			margin-top: 60rpx;
		}

		.wx-box {
			background: rgba(255, 255, 255, 0.3);
			border-radius: 32rpx;
			border: 2rpx solid #FFFFFF;
			box-sizing: border-box;
			padding: 44rpx 40rpx;
			box-sizing: border-box;
			font-weight: 400;
			font-size: 32rpx;
			color: #000000;
			line-height: 48rpx;

			.name {
				&::before {
					// font-family: "dy-iconfont";
					// content: "\e7e0";
					// font-size: 40rpx;
					// padding-right: 22rpx;
					// box-sizing: border-box;
				}
			}

			.password {
				margin-top: 44rpx;

				&::before {
					// font-family: "dy-iconfont";
					// content: "\e636";
					// font-size: 40rpx;
					// font-weight: 500;
					// padding-right: 22rpx;
					// box-sizing: border-box;
				}
			}

			.content {
				margin-top: 20rpx;
				height: 80rpx;
				background: rgba(255, 255, 255, 0.3);
				border-radius: 16rpx;
				padding: 18rpx 20rpx;
				box-sizing: border-box;
				font-weight: 400;
				font-size: 30rpx;
				color: #000000;
			}
		}

		.wifi-pop {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 614rpx;
			background: #FFFFFF;
			padding: 168rpx 0 80rpx 0;
			box-sizing: border-box;

			.connect {
				width: 392rpx;
				height: 80rpx;
				background: linear-gradient(180deg, #886AE6 0%, #4635FF 99%);
				border-radius: 80rpx;
				font-weight: 400;
				font-size: 32rpx;
				color: #FFFFFF;
				line-height: 80rpx;
				text-align: center;
			}
		}
	}
</style>